package com.cssw.fyzb.tps.api.im;

import com.cssw.fyzb.tps.service.im.AccountService;
import com.cssw.fyzb.tps.service.im.common.ImHttpComm;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author Jian Qin.
 */
@Function(description = "查询帐号在线状态", parameters = {
        @Parameter(name = "userIdList", type = Type.String, description = "待查询的账号id列表，以逗号分割"),
        @Parameter(name = "isNeedDetail", type = Type.String, description = "是否需要返回详细的登录平台信息。0表示不需要，1表示需要", required = false),
})
@Component
public class AccountQueryState implements Action {
    @Autowired
    private AccountService accountService;

    @Override
    public Response execute(Request request) throws Exception {
        String userIdList = request.getString("userIdList");
        String isNeedDetail = request.getString("isNeedDetail");
        String[] userIds = userIdList.split(",");
        if(userIds.length <= 0){
            return Response.fail("用户列表为空");
        }

        ImHttpComm.ImResult result = accountService.accountQueryState(userIds, isNeedDetail);
        if(result.getErrorCode() == 0){
            return Response.success()
                    .put("queryResult", result.getList("QueryResult"))
                    .put("errorList", result.getList("ErrorList"));
        }else{
            return Response.fail(result.getErrorInfo(), result.getErrorCode());
        }
    }
}
